home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / DTS.Lib / DTS.Lib.headers / StringUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  7.1 KB  |  192 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Header file for collection of String Utilities for DTS Sample code
  5. **
  6. **    Copyright © 1988-1992 Apple Computer, Inc.
  7. **    All rights reserved.
  8. */
  9.  
  10.  
  11. #ifndef __STRINGUTILS__
  12. #define __STRINGUTILS__
  13.  
  14. #ifdef applec
  15.  
  16. #ifndef __TYPES__
  17. #include <Types.h>
  18. #endif
  19.  
  20. #endif
  21.  
  22.  
  23. /* These are duplicates of c-library functions.  The reason for duplicating them
  24. ** is so that the StringUtils code can be small and linked in with other code that
  25. ** stays resident at all times.  It is possible that when you call code to do
  26. ** something as seemingly innocent as getting the length of a string, memory can
  27. ** move.  This is because the code you are calling isn't necessarily in memory.
  28. ** If the code segment that contains the code you are calling isn't in ram, then
  29. ** it has to be loaded.  Loading the code may cause memory compaction, and therefore
  30. ** memory can move.  The pointer to the string is already pushed on the stack prior
  31. ** to the call, so if you passed a pointer into an unlocked handle, after calling
  32. ** the code, that handle may have moved, and therefore the pointer is invalid.
  33. **
  34. ** To prevent the above problem, alternate names were used for these common library
  35. ** functions.  Link this code into the same segment that holds main(), and you will
  36. ** be guaranteed that they will be in memory whenever you call them. */
  37.  
  38. short    clen(char *cptr);
  39.     /* Return the length of the c-string.  (Same as strlen, but this function isn't
  40.     ** part of the string library.  The entire library may be more than you wish to
  41.     ** link into the code segment that holds main, so this (and other) standard
  42.     ** library function has been duplicated here. */
  43.  
  44. char    *ccat(char *s1, char *s2);
  45.     /* Catenate two c-strings. */
  46.  
  47. char    *ccpy(char *s1, char *s2);
  48.     /* Copy a c-string. */
  49.  
  50. short    pcmp(StringPtr s1, StringPtr s2);
  51.     /* Compare two pascal-strings. */
  52.  
  53. void    pcat(StringPtr d, StringPtr s);
  54.     /* Catenate two pascal-strings. */
  55.  
  56. void    pcpy(StringPtr d, StringPtr s);
  57.     /* Copy a pascal-string. */
  58.  
  59. void    c2p(char *cptr);
  60.     /* Convert a c-string to a pascal-string. */
  61.  
  62. void    p2c(StringPtr cptr);
  63.     /* Convert a pascal-string to a c-string. */
  64.  
  65.  
  66. /*****************************************************************************/
  67.  
  68. /* These are useful, relatively small routines for string manipulation.  As with the
  69. ** above calls, link them into the code segment that holds main().
  70. **
  71. ** With the below functions, you will have most of the functionality of sprintf
  72. ** using shorts and longs.  It will take more calls, but only what you call is linked
  73. ** in. */
  74.  
  75.  
  76. /**/
  77.  
  78. void    ccatchr(char *cptr, char c, short count);
  79.     /* Catenate a single character multiple times onto the designated string. */
  80.  
  81. void    ccatdec(char *cptr, long v);
  82.     /* Convert the value into text for the base-10 number and catenate it to
  83.     ** the designated string.  The value is assumed to be signed.  If you wish
  84.     ** to have an unsigned decimal value, call ccatnum with a base of 10. */
  85.  
  86. void    ccathex(char *cptr, char padChr, short minApnd, short maxApnd, long v);
  87.     /* Convert the value into text for base-16, format it, and catenate it to the
  88.     ** designated string.  ccatnum could be used, since it handles multiple bases,
  89.     ** but ccathex allows for additional common formatting and padding of the
  90.     ** hex value. */
  91.  
  92. void    ccatnum(char *cptr, long v, short base);
  93.     /* Convert the value into text for the designated base.  Catenate the text to
  94.     ** the designated string. */
  95.  
  96. void    ccpychr(char *cptr, char c, short count);
  97.     /* Copy a single character multiple times onto the designated string. */
  98.  
  99. void    ccpydec(char *cptr, long v);
  100.     /* Convert the value into text for the base-10 number and copy it into
  101.     ** the designated string.  The value is assumed to be signed.  If you wish
  102.     ** to have an unsigned decimal value, call ccpynum with a base of 10. */
  103.  
  104. void    ccpyhex(char *cptr, char padChr, short minApnd, short maxApnd, long v);
  105.     /* Convert the value into text for base-16, format it, and copy it into the
  106.     ** designated string.  ccpynum could be used, since it handles multiple bases,
  107.     ** but ccpyhex allows for additional common formatting and padding of the
  108.     ** hex value. */
  109.  
  110. void    ccpynum(char *cptr, long v, short base);
  111.     /* Convert the value into text for the designated base.  Copy the text into
  112.     ** the designated string. */
  113.  
  114. long    c2dec(char *cptr, short *charsUsed);
  115.     /* Convert the c-string to a decimal number. */
  116.  
  117. long    c2hex(char *cptr, short *charsUsed);
  118.     /* Convert the c-string to a hex number. */
  119.  
  120. long    c2num(char *cptr, short base, short *charsUsed);
  121.     /* Convert the c-string to a number.  The string can either be in decimal or hex notation. */
  122.  
  123. short    GetLastBase(Boolean handleChars);
  124.     /* Use this to find out what base c2num determined the text to be. */
  125.  
  126. /**/
  127.  
  128. short    pcmp(StringPtr s1, StringPtr s2);
  129.     /* Compare a pascal-string. */
  130.  
  131. void    pcatchr(StringPtr pptr, char c, short count);
  132.     /* Catenate a single character multiple times onto the designated string. */
  133.  
  134. void    pcatdec(StringPtr pptr, long v);
  135.     /* Convert the value into text for the base-10 number and catenate it to
  136.     ** the designated string.  The value is assumed to be signed.  If you wish
  137.     ** to have an unsigned decimal value, call pcatnum with a base of 10. */
  138.  
  139. void    pcathex(StringPtr pptr, char padChr, short minApnd, short maxApnd, long v);
  140.     /* Convert the value into text for base-16, format it, and catenate it to the
  141.     ** designated string.  pcatnum could be used, since it handles multiple bases,
  142.     ** but pcathex allows for additional common formatting and padding of the
  143.     ** hex value. */
  144.  
  145. long    pcatnum(StringPtr pptr, long v, short base);
  146.     /* Convert the value into text for the designated base.  Catenate the text to
  147.     ** the designated string. */
  148.  
  149. void    pcpychr(StringPtr pptr, char c, short count);
  150.     /* Copy a single character multiple times onto the designated string. */
  151.  
  152. void    pcpydec(StringPtr pptr, long v);
  153.     /* Convert the value into text for the base-10 number and copy it into
  154.     ** the designated string.  The value is assumed to be signed.  If you wish
  155.     ** to have an unsigned decimal value, call pcpynum with a base of 10. */
  156.  
  157. void    pcpyhex(StringPtr pptr, char padChr, short minApnd, short maxApnd, long v);
  158.     /* Convert the value into text for base-16, format it, and copy it into the
  159.     ** designated string.  pcpynum could be used, since it handles multiple bases,
  160.     ** but pcpyhex allows for additional common formatting and padding of the
  161.     ** hex value. */
  162.  
  163. void    pcpynum(StringPtr pptr, long v, short base);
  164.     /* Convert the value into text for the designated base.  Copy the text into
  165.     ** the designated string. */
  166.  
  167. long    p2dec(StringPtr pptr, short *charsUsed);
  168.     /* Convert the pascal-string to a decimal number. */
  169.  
  170. long    p2hex(StringPtr pptr, short *charsUsed);
  171.     /* Convert the pascal-string to a hex number. */
  172.  
  173. long    p2num(StringPtr pptr, short base, short *charsUsed);
  174.     /* Convert the pascal-string to a number.  String can either be in decimal or hex notation. */
  175.  
  176. /**/
  177.  
  178. short    GetHexByte(char *cptr);
  179.  
  180. Boolean    EqualHandle(void *h1, void *h2);
  181.     /* This function checks to see if two handles are identical. */
  182.  
  183. Boolean    EqualData(void *v1, void *v2, long size);
  184.     /* This function checks to see if two blocks of data are identical. */
  185.  
  186. void    SetMem(void *vptr, unsigned char c, unsigned long len);
  187.  
  188. #endif
  189.  
  190.  
  191.  
  192.